home *** CD-ROM | disk | FTP | other *** search
- static const char rcs_id[] = "$Header: /disk1/schutte/src_tree/cppima/examples/RCS/caverage.cc,v 1.2 1994/06/07 15:20:16 schutte Exp schutte $";
- // cppima: a C++ image processing library
-
- // Copyright (C) 1992 Klamer Schutte
-
- // klamer@mi.el.utwente.nl
-
- // This library is free software; you can redistribute it and/or
- // modify it under the terms of the GNU Library General Public
- // License as published by the Free Software Foundation; either
- // version 2 of the License, or (at your option) any later version.
-
- // This library is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- // Library General Public License for more details.
-
- // You should have received a copy of the GNU Library General Public
- // License along with this library; if not, write to the Free
- // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
-
- // $Log: caverage.cc,v $
- // Revision 1.2 1994/06/07 15:20:16 schutte
- // Changed from VIFF to IMA.
- //
- // Revision 1.1 1992/09/25 15:35:30 klamer
- // Initial revision
- //
-
- // Program to calculate the average value of an image.
-
- #include <iostream.h>
-
- #include <cppima/charimaimage.h>
- #include <cppima/imageiter.h>
- #include <cppima/charimageiter.h>
-
- double
- #ifdef __GNUG__
- // Sun C++ 2.1 Can't handle this kind of overloading.
- // (OK, it's on the edge...
- totalImagePixels( const CharImageBase &imm )
- #else
- totalImagePixels( const CharImaImage &imm )
- #endif
- {
- CharImageIter iter(imm);
-
- int total = 0;
- int nr = 0;
-
- while(iter())
- {
- nr++;
- total+=iter.read();
- }
-
- return double(total) / nr;
- }
-
- double
- totalImagePixels( const Image &imm )
- {
- ImageIter iter(imm);
-
- double total = 0;
- int nr = 0;
-
- while(iter())
- {
- nr++;
- total+=iter.readdouble();
- }
-
- return total / nr;
- }
-
- main(int , char *argv[])
- {
- double val = totalImagePixels(CharImaImage(argv[1]));
-
- cout << "Mean value of " << argv[1] << " is: " << val << endl;
- }
-
-
-